// 为类型提供变量
// 没有泛型，你定义的类型都是死的，没有灵活性
// 定义类型时加入泛型就像定义函数时加入形参，可以让类型定义的更精确，更通用

type NumArr =   Array<number>  //这里如果没有泛型，就只能定义一个数组，至于数组里是什么类型就无法限制，加入泛型就可以更加精确限制
type ObjectWithNameArray = Array<{name:string}>

// 在自己声明的add类型里面加入泛型
 interface Backpack<type> {
     add :(obj:type)=>void;
     get:()=>type
 }

    // This line is a shortcut to tell TypeScript there is a
// constant called `backpack`, and to not worry about where it came from.
 const backpack: Backpack<string> ={
    add:(obj)=>{},
    get:()=>'1'
};

// object is a string, because we declared it above as the variable part of Backpack.
const object = backpack.get();
console.log(object);
